<template>
    <div>
        <el-card>
            <div class="baseCss">
                <span>查询条件</span>
            </div>
            <div class="baseCss">
                <el-button type="primary" size="mini">查询</el-button>
            </div>
        </el-card>

        <el-card style="margin-top: 1rem">
            <div class="baseCss">
                <el-button type="primary" size="mini" @click="handleAddData">添加</el-button>
            </div>
            <el-table :data="tableData" border>
                <el-table-column type="index" label="序号" width="50" align="center" />
                <el-table-column label="分项工程名称" prop="share_name_" align="center"></el-table-column>
                <el-table-column label="制单人" prop="create_user_" align="center"></el-table-column>
                <el-table-column label="制单时间" prop="create_time_" align="center"></el-table-column>
                <el-table-column label="操作" width="220">
                    <template #default="scope">
                        <el-button
                            size="mini"
                            type="text"
                            @click="handleEdit(scope.$index, scope.row)"
                        >编辑</el-button>
                        <el-button size="mini" type="text" @click="handleSearch(scope.$index, scope.row)">查看</el-button>
                        <el-button
                            size="mini"
                            type="text"
                            @click="handleDelete(scope.$index, scope.row)"
                        >删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div style="text-align: right; margin-top: 1rem">
                <el-pagination
                    background
                    small
                    layout="total, sizes, prev, pager, next"
                    @size-change="pageSizeChange"
                    @current-change="pageChange"
                    :current-page.sync="page"
                    :page-sizes="[10, 20, 30, 40]"
                    :page-size.sync="pagesize"
                    :total="total"
                ></el-pagination>
            </div>
        </el-card>
    </div>
</template>

<script>
export default {
    data() {
        return {
            total: 0,
            tableData: [],
            page: 1,
            pagesize: 10,
        }
    },
    created() {
        this.getData()
    },
    methods: {
        // 页码变更
        pageChange(val) {
            this.page = val;
            this.getData();
        },
        // 条目变更
        pageSizeChange(val) {
            this.pagesize = val;
            this.getData();
        },
        getData() {
            const param = { curPage: this.page, pageSize: this.pageSize, params: {} }
            this.$axios.post('/form/formCustSql/view/list_ppcgScheduleTemplateMaintenanceMst', param).then(res => {
                if (res.isOk) {
                    this.tableData = res.data.list
                    this.tableData.map(item => {
                        if (item.create_time_)
                            item.create_time_ = this.$moment(item.create_time_).format('YYYY-MM-DD HH:mm:ss')
                    })
                    this.total = res.data.count
                    this.$ElMessage({
                        message: '查询成功',
                        type: 'success',
                    })
                } else {
                    this.$ElMessage({
                        message: res.msg,
                        type: 'error',
                    })
                }
            })
        },
        handleEdit(index, row) {
            this.$router.push({ path: `/scheduleTemplateMaintenanceDtl&${row.id_}&false` });
        },
        handleSearch(index, row) {
            this.$router.push({ path: `/scheduleTemplateMaintenanceDtl&${row.id_}&true` });
        },
        handleDelete(index, row) {
            this.$ElMessageBox.confirm(
                '确定删除该条数据吗？',
                '警告',
                {
                    confirmButtonText: '删除',
                    cancelButtonText: '取消',
                    type: 'warning',
                }
            ).then(() => {
                this.$axios.post(`/form/formDefData/removeData/ppcgScheduleTemplateMaintenanceMst/${row.id_}`).then(res => {
                    if (res.isOk) {
                        this.$ElMessage({
                            message: '删除成功',
                            type: 'success',
                        })
                        this.getData()
                    } else {
                        this.$ElMessage({
                            message: res.msg,
                            type: 'error',
                        })
                    }
                })
            }).catch(() => {
            })
        },
        handleAddData() {
            this.$router.push({ path: `/scheduleTemplateMaintenance` });
        }
    },
}
</script>

<style>
.baseCss {
    text-align: left;
    margin-bottom: 1rem;
}
</style>